//
// Created by zntx0 on 2025/9/27.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "zJSON.h"

int main(void)
{
    char buff[300] = {0};

    zJSONFormatted json_formatted = zJSON_CreateFormatted(buff, 300);

    zJSON_AddNumberToObject(&json_formatted, "n", 68);
    zJSON_AddNumberToObject(&json_formatted, "n2", 68.3);
    zJSON_AddObjectStartToObject(&json_formatted, "person");
    zJSON_AddStringToObject(&json_formatted, "name", "Alice");
    zJSON_AddNumberToObject(&json_formatted, "age", 30);
    zJSON_AddArrayStartToObject(&json_formatted, "hobbies");
    zJSON_AddStringToArray(&json_formatted, "reading");
    zJSON_AddStringToArray(&json_formatted, "traveling");
    zJSON_AddStringToArray(&json_formatted, "coding");
    zJSON_AddArrayEndToObject(&json_formatted);
    zJSON_AddObjectStartToObject(&json_formatted, "address");
    zJSON_AddStringToObject(&json_formatted, "city", "New York");
    zJSON_AddStringToObject(&json_formatted, "zip", "10001");
    zJSON_AddObjectEndToObject(&json_formatted );
    zJSON_AddObjectEndToObject(&json_formatted );
    zJSON_AddTrueToObject(&json_formatted, "isActive");
    zJSON_AddArrayStartToObject(&json_formatted, "scores");
    zJSON_AddNumberToArray(&json_formatted, 95);
    zJSON_AddNumberToArray(&json_formatted, 88);
    zJSON_AddNumberToArray(&json_formatted, 76);
    zJSON_AddArrayEndToObject(&json_formatted);
    zJSON_AddNullToObject(&json_formatted, "metadata");
    zJSON_AddObjectEndToObject(&json_formatted );

    printf(" buff ---\n%s---\n", buff);

    // zJSON_Minify(buff);
    //
    // printf(" buff ---\n%s---\n", buff);


    zJSON json = zJSON_Parse(buff);
    printf("type %d zJSON_Object %d\n", json.type, zJSON_Object);
    printf("type %llu %llu \n", json.length, json.offset);
    json.length = json.offset;
    json.offset = 0;

    zJSON item2 = zJSON_Get(&json, "person", "name", NULL);
    printf("%s:%d >>>>",  strrchr(__FILE__, '/'), __LINE__);
    zJSON_Print(&item2);

    item2 = zJSON_Get(&json, "person", "hobbies", NULL);
    printf("%s:%d ",  __FILE__, __LINE__);
    zJSON_Print(&item2);

    printf("item2 type %d\n", item2.type);
    printf("item2 size %d\n", zJSON_GetArraySize(&item2));

    zJSON item3 = zJSON_GetArrayItem(&item2, 3);
    printf("%s:%d ",  __FILE__, __LINE__);
    zJSON_Print(&item3);





    //
    // item2 = zJSON_GetV2(&json, "person", "address", "city", NULL);
    // printf("%s:%d ",  __FILE__, __LINE__);
    // zJSON_Print(&item2);


    // zJSON item3 = zJSON_GetV2(&json, "data", "url");
    // zJSON_Print(&item3);

    return 1;
}